package 力扣._98_验证BST;

import 力扣.公用数据结构.TreeNode;

import java.util.Stack;

public class Solution2 {


    public boolean isValidBST(TreeNode root) {
        //中序遍历
        Stack<TreeNode> stack = new Stack<>();
        long inorder = Long.MIN_VALUE;
        while (!stack.isEmpty() || root != null) {
            while (root!=null){
                stack.push(root);
                root = root.left;
            }
            root = stack.pop();

            if(root.val<=inorder)
                return false;
            inorder = root.val;
            root = root.right;
        }
        return true;
    }
}
